package com.augmented.jellybean.util;

import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;

import android.os.AsyncTask;
import android.util.Log;

public class JSONParser extends AsyncTask<StringBuilder, Void, StringBuilder> {

	protected StringBuilder doInBackground(StringBuilder... params) {
		HttpURLConnection conn = null;
		StringBuilder jsonResults = new StringBuilder();
		try {
			URL url = new URL(params[0].toString());
			Log.i("The URL is: ", url.toString());
			conn = (HttpURLConnection) url.openConnection();
			InputStreamReader in = new InputStreamReader(conn.getInputStream());

			int read;
			char[] buff = new char[1024];
			while ((read = in.read(buff)) != -1) {
				jsonResults.append(buff, 0, read);
			}
		} catch (MalformedURLException e) {
			return jsonResults;
		} catch (IOException e) {
			return jsonResults;
		} finally {
			if (conn != null) {
				conn.disconnect();
			}
		}
		return jsonResults;
	}

	protected void onPostExecute(StringBuilder results) {
		super.onPostExecute(results);
	}
}